package com.example.teach.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teach.entity.Course;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CourseMapper extends BaseMapper<Course> {

    @Select("select * from course where course_name=#{courseName}")
    Course selectByName(String courseName);

    @Select("select count(*) from major_course where major_id=#{majorId} and course_id=#{courseId}")
    Integer selectNum(Integer majorId, Integer courseId);

    @Insert("insert into major_course(major_id,course_id) values(#{majorId},#{courseId})")
    void save(Integer majorId, Integer courseId);

    @Select("select course.id, course.course_name, course.credits, course.hours from course join major_course on course.id = major_course.course_id where major_course.major_id=#{majorId}")
    List<Course> list(Integer majorId);

    @Delete("delete from major_course where major_id=#{majorId} and course_id=#{courseId}")
    void deleteOne(Integer majorId, Integer courseId);

    @Delete("delete from major_course where major_id=#{majorId}")
    void remove(Integer majorId);
}
